package com.hongawen.async.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年04月02日 11:17
 */
@Component
public class TestInterruptThread {


    @Async("asyncExecutor")
    public CompletableFuture<String> testInterruptThread() {
        System.out.println("测试线程正在执行============");
        try {
            TimeUnit.SECONDS.sleep(5);
            System.out.println("测试线程最终执行完所有任务============");
        } catch (InterruptedException e) {
            System.out.println("测试线程被打断============");
        }
        return CompletableFuture.completedFuture("over");

    }


    @Async("asyncExecutor")
    public void doTaskTwo() {
        System.out.println("测试线程正在执行============");
        try {
            TimeUnit.SECONDS.sleep(5);
            System.out.println("测试线程最终执行完所有任务============");
        } catch (InterruptedException e) {
            System.out.println("测试线程被打断============");
        }


    }


}
